package com.sr.servlet;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sr.data.*;

public class baseinfoCI extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		//response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		baseDataService bds = new baseDataService();
		String type = request.getParameter("type");
		//跳转到修改页面
		if("goBaseUpdate".equals(type)){
			String id =request.getParameter("id");
			srProject srp = bds.getProjectById(id);
			request.getSession().setAttribute("updateBaseProject", srp);
			response.sendRedirect("/scientific/jsp/base/baseUpdate.jsp");
			
		}
				
		else if("baseUpdate".equals(type)){
			srProject srp = new srProject();
			srp.setprojectID(request.getParameter("id"));
			srp.setprojectName(request.getParameter("pName"));
			srp.setDepartment(request.getParameter("department"));
			srp.setBeginDate(request.getParameter("bDate"));
			srp.setEndDate(request.getParameter("eDate"));
			srp.setProjectLeader(request.getParameter("pLeader"));
			srp.setMainMembers(Integer.parseInt(request.getParameter("mainMembers")));
			srp.setFromOrg(request.getParameter("fromOrg"));
			srp.setLevelProject(request.getParameter("levelProject"));
			srp.setTypeProject( request.getParameter("typeProject"));
			srp.setDiscipline(request.getParameter("discipline"));
			
			if(bds.UpdateProject(srp)){
				System.out.println("111");
				response.sendRedirect("/scientific/searchProject?type=allBaseInfo");				
			}else{
				response.sendRedirect("/scientific/jsp/base/baseUpdate.jsp");
			}			
		}
		
		else if("deleteBase".equals(type)){
			String projectID=request.getParameter("id");
			if(bds.DelProject(projectID))
			{
				response.sendRedirect("/scientific/searchProject?type=allBaseInfo");				
			}
		}
		
		else if("goBaseDetail".equals(type)){
			String id = request.getParameter("id");
			srProject srp = bds.getProjectById(id);
			request.getSession().setAttribute("detailBaseInfo", srp);
			response.sendRedirect("/scientific/jsp/base/detailBase.jsp");
		}
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		this.doGet(request, response);		
	}

	


}
